



<template>
	
	<view class="wrap">
		<view class="goback-wrap" @click="goback">
			<image src="../../static/goback.png" mode=""></image>
		</view>
		<view class="logo">
			<image src="../../static/applogo.png" mode="scaleToFill"></image>
		</view>
		<view class="login-wrap">
			
			<view class="account">
				
				<view class="ipt-wrap">
					<input v-model="phone" placeholder-style="color:#fff"  type="text" placeholder="请输入手机号码" />
				</view>
			</view>
			<view class="account">
				
				<view class="ipt-wrap">
					<input v-model="name" placeholder-style="color:#fff"  type="text" placeholder="请设置昵称" />
				</view>
			</view>
			<view class="account">
				
				<view class="ipt-wrap">
					<input v-model="code" placeholder-style="color:#fff"  type="text" placeholder="请输入验证码" />
				</view>
				<view class="right-btn" @click="getCode">
					{{btntip}}
				</view>
			</view>
			<view class="account">
				
				<view class="ipt-wrap">
					<input v-model="pwd" placeholder-style="color:#fff"  type="password" placeholder="请设置登录密码" />
				</view>
			</view>
			<view class="account">
				
				<view class="ipt-wrap">
					<input v-model="jy_pwd" placeholder-style="color:#fff"  type="password" placeholder="请设置支付密码" />
				</view>
			</view>
			<view class="account">
				<view style="padding-right:20rpx" class="label">
					推荐码
				</view>
				<view class="ipt-wrap" v-if="hascode">
					{{invite_code}}
					
				</view>
				<view class="ipt-wrap" v-if="!hascode">
					
					<input v-model="invite_code" placeholder-style="color:#fff"  type="text" placeholder="输入推荐码"  />
				</view>
			</view>
			<view class="sub-btn" @click="register">
				立即注册
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				hascode:false,
				btntip: '点击获取验证码',
				invite_code:'',
				name:'',
				phone: '',
				code:'',
				pwd:'',
				jy_pwd:'',
				timer:null,
				time:59
			}
		},
		onLoad(options) {
			this.hascode=options.invite?true:false
			this.invite=options.invite?options.invite:''
		},
		methods: {
			goback(){
				uni.navigateBack();
			},
			getCode(){
				let that=this
				
				if(this.phone==''){
					uni.showToast({
					    title: '请输入手机号',
					    duration:4000,
						icon:'none'
					});
					return
				}
				if(that.time!=59){
					return
				}
				
				that.timer=setInterval(function(){
					
					if(that.time==1){
						that.btntip='点击获取验证码'
						clearInterval(that.timer)
						that.time=59
					}else{
						that.btntip=--that.time+'s后获取'
					}
					
				},1000)
				
				that.apiget('/api/auth/SendMobileMsg',{
					phone:that.phone,
					
				},true).then(res => {
					if(res.Code==10200){
						uni.showToast({
						    title: res.Message,
						    duration:4000,
							icon:'none'
						});
						
					}
					
				}).catch(err=>{
					console.log(err)
				});
			},
			register(){
				let that=this
				
				if(this.phone==''){
					uni.showToast({
					    title: '请输入手机号',
					    duration:4000,
						icon:'none'
					});
					return
				}
				if(this.code==''){
					uni.showToast({
					    title: '请输入手机验证码',
					    duration:4000,
						icon:'none'
					});
					return
				}
				if(this.name==''){
					uni.showToast({
					    title: '请输入昵称',
					    duration:4000,
						icon:'none'
					});
					return
				}
				if(this.pwd==''){
					uni.showToast({
					    title: '请设置登录密码',
					    duration:4000,
						icon:'none'
					});
					return
				}
				let reg=/^\d{6}$/
				if(!reg.test(this.jy_pwd)){
					uni.showToast({
					    title: '支付密码为六位数字',
					    duration:4000,
						icon:'none'
					});
					return
				}
				
				
				
				
				
				
				that.apipost('/api/auth/signup',{
					phone:that.phone,
					pwd:that.pwd,
					name:that.name,
					jy_pwd:that.jy_pwd,
					invite_code:that.invite_code,
					code:that.code
				},true).then(res => {
					if(res.Code==10200){
						// #ifdef H5
							window.location.href="https://download.huayuely.cn"
						// #endif

						
						uni.showToast({
						    title: res.Message,
						    duration:4000,
							icon:'none'
						});
						
					}
					
				}).catch(err=>{
					console.log(err)
				});
				
			}
		}
	}
</script>

<style>
	.goback-wrap{
		position:absolute;
		width:20rpx;
		height:36rpx;
		left:32rpx;
		top:82rpx;
	}
	.right-btn{
		
		width:244rpx;
		height:50rpx;
		display:flex;
		justify-content: center;
		align-items: center;
	}
	.sub-btn{
		height:66rpx;
		color:#fff;
		display:flex;
		justify-content: center;
		align-items: center;
		border-radius:8rpx;
		border:1rpx solid #fff;
		margin-top:88rpx;
	}
	
	.ipt-wrap{
		height:92rpx;
		display:flex;
		align-items: center;
	}
	.account .ipt-wrap,.pwd-wrap .ipt-wrap{
		flex:1;
	}
	
	
	.account input,.pwd-wrap input{
		width:100%;
		height:100%;
		
	}
	.account{
		border-bottom:1rpx solid #fffeff;
		color:#fff;
		display:flex;
		align-items: center;
		justify-content: space-between;
		margin-bottom:10rpx;
	}
	
	.logo{
		width:280rpx;
		height:280rpx;
		
		margin:0 auto;
		margin-top:148rpx;
	}
	
	.wrap{
		height:100%;
		overflow: hidden;
		/* background:url(../../static/registertop.png) no-repeat right 0; */
		/* background-size:100% 100%; */
		
	}
	page{
		
		background:url(../../static/registerbg.jpg) no-repeat;
		background-size:100% 100%;
	}
	.login-wrap{
		padding:0 44rpx 0 44rpx;
		box-sizing: border-box;
		width:560rpx;

		margin:0 auto;
		margin-top:70rpx;
	}
	
</style>
